﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace SeriesWatcher.DataModel
{
    class Episode
    {
        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        
        private int number;
        public int Number
        {
            get { return number; }
            set { number = value; }
        }

        private DateTime date;
        public DateTime Date
        {
            get { return date; }
            set { date = value; }
        }

        private string version;
        public string Version
        {
            get { return version; }
            set { version = value; }
        }

        private bool seen;
        public bool Seen
        {
            get { return seen; }
            set { seen = value; }
        }

        private bool titles;
        public bool Titles
        {
            get { return titles; }
            set { titles = value; }
        }

        private bool nuked;
        public bool Nuked
        {
            get { return nuked; }
            set { nuked = value; }
        }

        /// <summary>
        /// Default constructor
        /// </summary>
        
        public Episode()
        {
            this.name = "";
            this.number = 0;
            this.date = new DateTime(1900, 1, 1);
            this.version = "";
            this.seen = false;
            this.titles = false;
            this.nuked = false;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="number">Number of episode</param>
        /// <param name="version">Release version</param>
        public Episode(int number, string version)
        {
            this.name = "";
            this.number = number;
            this.date = new DateTime(1900, 1, 1);
            this.version = version;
            this.seen = false;
            this.titles = false;
            this.nuked = false;
        }
        /// <summary>
        /// Check if episode was aired
        /// </summary>
        /// <returns></returns>
        public bool EpisodeAired()
        {
            return this.date < DateTime.Now;
        }

        public XmlElement SaveToXml(XmlDocument doc)
        {
            XmlElement element = doc.CreateElement("episode");

            XmlElement att0 = doc.CreateElement("number");
            XmlElement att1 = doc.CreateElement("name");
            XmlElement att2 = doc.CreateElement("date");
            XmlElement att3 = doc.CreateElement("version");
            XmlElement att4 = doc.CreateElement("seen");
            XmlElement att5 = doc.CreateElement("titles");
            XmlElement att6 = doc.CreateElement("nuked");

            att0.InnerText = Number.ToString();
            att1.InnerText = Name;
            att2.InnerText = Date.ToString();
            att3.InnerText = Version.ToString();
            att4.InnerText = Seen.ToString();
            att5.InnerText = Titles.ToString();
            att6.InnerText = Nuked.ToString();

            element.AppendChild(att0);
            element.AppendChild(att1);
            element.AppendChild(att2);
            element.AppendChild(att3);
            element.AppendChild(att4);
            element.AppendChild(att5);
            element.AppendChild(att6);

            return element;

        }
    }
}
